package zjh_20230405;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ScheduleAtFixedRate {
    public static void main(String[] args) {
        ScheduledExecutorService pool = Executors.newScheduledThreadPool(3);


        for (int i = 0; i < 5; i++) {
            int number = i;
            pool.scheduleWithFixedDelay(new Runnable() {
                @Override
                public void run() {
                    System.out.println("线程" + Thread.currentThread().getName() + "序号" + number);
                }
            },4,2,TimeUnit.SECONDS);
        }

        try {
            pool.awaitTermination(10,TimeUnit.SECONDS);
            pool.shutdown();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
//        pool.isShutdown();


/*
        pool.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("线程" + Thread.currentThread().getName());
            }
        },4,1, TimeUnit.SECONDS);
//   pool.shutdown();
//    pool.isShutdown();

 */
    }

}
